package com.proxy.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * DesignPatterns
 *
 * @Title: com.proxy.thread
 * @Date: 2021/1/11 0011 22:10
 * @Author: wfg
 * @Description:
 * @Version:
 */
public class MyThreadLocal {

    public static void main(String[] args) {
        ThreadLocal<String> local = new ThreadLocal<>();
        Random random = new Random();
        IntStream.range(0,5).forEach((a)->{
            new Thread(()->{
                String str = random.nextInt(10)+"";
                local.set(str);
                System.out.println("线程"+Thread.currentThread().getName()+"    "+ local.get());
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        });

    }


}
